//
//  LYFDiscoverySearchView.swift
//  weibohhhh
//
//  Created by fersh on 16/1/2.
//  Copyright © 2016年 fersh. All rights reserved.
//

import UIKit

class LYFDiscoverySearchView: UIView {
    @IBOutlet weak var textFilesRightConstraint: NSLayoutConstraint!
    
    @IBOutlet weak var textFiled: UITextField!
    
    @IBOutlet weak var cancelButton: UIButton!
    
    //从xib里面加载view
    class func searchView()->LYFDiscoverySearchView {
        
        return  NSBundle.mainBundle().loadNibNamed("LYFDiscoverySearchView", owner: nil, options: nil).last! as! LYFDiscoverySearchView
        
    }
    
    @IBAction func cancelButtonClick(sender: AnyObject) {
        
        //退出键盘
        self.textFiled.resignFirstResponder()
        //更改
        self.textFilesRightConstraint.constant = 0
        UIView.animateWithDuration(0.25) { () -> Void in
            self.textFiled.layoutIfNeeded()
            
        }
        
    }
    
    
    @IBAction func textFIledBeginEdit(sender: AnyObject) {
        
        print("开始编辑")
        //更改约束
        self.textFilesRightConstraint.constant = self.cancelButton.bounds.size.width
        UIView.animateWithDuration(0.25) { () -> Void in
            
            self.textFiled.layoutIfNeeded()
        }
    }
    override func awakeFromNib() {
        // xib 完全转成一个 view
        // xib 里面的子控件连线完成
        let leftView = UIImageView()
        
        leftView.image = UIImage(named: "searchbar_textfield_search_icon")
        
        leftView.frame.size = CGSizeMake(frame.height, frame.height)
    
          // center 是代表居中，以原样大小显示
        leftView.contentMode = .Center
        textFiled.leftView = leftView
        textFiled.leftViewMode = .Always
        //设置编辑框的边框
        
//        textFiled.layer.borderWidth = 2
//        textFiled.layer.borderColor = UIColor.purpleColor().CGColor
//        textFiled.layer.cornerRadius = 5
        
    }

}
